﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NekoVampire.TwitterClient.Controls
{
    [Serializable()]
    public class ListViewItemComparer : IComparer, IComparer<ListViewItemEx>, IComparer<ListViewItem>
    {
        public int col
        {
            get;
            set;
        }
        public bool flg
        {
            get;
            set;
        }

        public ListViewItemComparer()
        {
            col = 0;
            flg = true;
        }
        public ListViewItemComparer(int column)
        {
            col = column;
            flg = true;
        }
        public ListViewItemComparer(int column, bool flag)
        {
            col = column;
            flg = flag;
        }

        public int Compare(object x, object y)
        {
            return Compare((ListViewItemEx)x, (ListViewItemEx)y);
        }

        public int Compare(ListViewItem x, ListViewItem y)
        {
            return Compare((ListViewItemEx)x, (ListViewItemEx)y);
        }

        public int Compare(ListViewItemEx x, ListViewItemEx y)
        {
            if (col == 0)
                if (flg)
                    return (x.Tag.CompareTo(y.Tag));
                else
                    return (-x.Tag.CompareTo(y.Tag));
            else
                if (flg)
                    return (String.Compare(x.SubItems[col].Text, y.SubItems[col].Text));
                else
                    return (-String.Compare(x.SubItems[col].Text, y.SubItems[col].Text));
        }
    }
}